package com.XiaoLongGroup.webtech.mapper;/**
 * @author : SLCcccc
 * @date : 2023/5/6 10:15
 */

import com.XiaoLongGroup.webtech.Cache.RelativeCache;
import com.XiaoLongGroup.webtech.entity.Article;
import com.XiaoLongGroup.webtech.entity.User;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *@ClassName ArticleMapper
 *@Description TODO
 *@Author SLCcccc
 *@Date 2023/5/6 10:15
 */
@Repository
@CacheNamespace(implementation = RelativeCache.class, eviction = RelativeCache.class, flushInterval = 30 * 60 * 1000)
public interface ArticleMapper {

    /**
     * ToDo: 查找用户列表
     * @return {@link List <User>}
     * @author Yuhaotian
     * @date. 2022/11/22 11:27
     * @since 1.0.0
     */
    List<Article> getAllArticleList();


    /**
     * getArticlesById
     * @param authorId
     * @param page
     * @param size
     * @return
     */
    List<Article> getArticlesByAuthorId(@Param("authorId") String authorId,
                                        @Param("page") int page,@Param("size") int size);

    /**
     * 获取列表
     * @param page
     * @param size
     * @return
     */
    List<Article> getArticleList(@Param("page") int page,@Param("size") int size);

    /**
     * 获取文章列表 模糊查询
     * @param search
     * @param page
     * @param size
     * @return
     */
    List<Article> getArticleListByNameLike(@Param("search") String search, @Param("page") int page, @Param("size") int size);

    /**
     * 获取文章数量(模糊)
     * @param search
     * @return
     */
    int getArticleCount(String search);

    /**
     * 获取文章数量(模糊)
     * @param search
     * @param authorId
     * @return
     */
    int getArticleCountByAuthorIdAndNameLike(String search, String authorId);

    /**
     * 获取文章数量By authorId
     * @param authorId
     * @return
     */
    Integer getArticleCountByAuthorId(@Param("authorId") String authorId);

    /**
     * 更新文章
     * @param article
     * @return
     */
    int updateArticle(Article article);

    /**
     * 添加文章
     * @param article
     * @return
     */
    int addArticle(Article article);

    /**
     * 删除
     * @param id
     * @return
     */
    int deleteArticleByArticleId(@Param("id") int id);

    /**
     * 根据Id获取文章
     * @param articleId
     * @return
     */
    Article getArticleByArticleId(@Param("articleId") int articleId);

    /**
     * 获取文章列表 书名模糊查询+用户
     * @param authorId
     * @param search
     * @param page
     * @param size
     * @return
     */
    List<Article> getArticleListByNameLikeAndAuthorId(@Param("authorId") String authorId, @Param("search") String search,
                                                      @Param("page") int page, @Param("size") int size);
}
